package bot;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

/**
 * Holds all of the information about a given place that is needed for the Wikipedia updates.
 * @author Jamison Bradley
 */
public class City {
	/**
	 * The name of the place
	 */
	private String name;
	
	/**
	 * The type of the place ex: city or CDP
	 */
	private String type;
	
	/**
	 * The total population of the place.
	 */
	private String totalPopulation;
	
	/**
	 * The percentage population under the age of 18.
	 */
	private String percentUnder18;
	
	/**
	 * The percentage population between the ages of 18 and 24.
	 */
	private String percent18to24;
	
	/**
	 * The percentage population between the ages of 25 and 44.
	 */
	private String percent25to44;
	
	/**
	 * The percentage population between the ages of 45 and 64.
	 */
	private String percent45to64;
	
	/**
	 * The percentage of population over 65 years old.
	 */
	private String percentOver65;
	
	/**
	 * The median age of the place.
	 */
	private String medianAge;
	
	/**
	 * The percentage of the population that is male.
	 */
	private String percentMale;
	
	/**
	 * The percentage of the population that is female.
	 */
	private String percentFemale;
	
	/**
	 * The percentage of the population that is White.
	 */
	private String percentWhite;
	
	/**
	 * The percentage of the population that is African American.
	 */
	private String percentBlack;
	
	/**
	 * The percentage of the population that is Native American.
	 */
	private String percentNative;
	
	/**
	 * The percentage of the population that is Asian.
	 */
	private String percentAsian;
	
	/**
	 * The percentage of the population that is Pacific Islander.
	 */
	private String percentPacific;
	
	/**
	 * The percentage of the population that is an other race.
	 */
	private String percentOther;
	
	/**
	 * The percentage of the population that is two or more races.
	 */
	private String percentTwoOrMore;
	
	/**
	 * The percentage of the population that is Hispanic.
	 */
	private String percentHispanic;
	
	/**
	 * The number of households in the place.
	 */
	private String households;
	
	/**
	 * The number of families in the place.
	 */
	private String families;
	
	/**
	 * The percentage of the households with children.
	 */
	private String percentWithChildren;
	
	/**
	 * The percentage of the households that are husband and wife.
	 */
	private String percentHusbandAndWife;
	
	/**
	 * The percentage of the households that are a male with no wife.
	 */
	private String percentMaleNoWife;
	
	/**
	 * The percentage of the households that are a female with no husband.
	 */
	private String percentFemaleNoHusband;
	
	/**
	 * The percentage of the households that aren't a family.
	 */
	private String percentNonFamily;
	
	/**
	 * The percentage of the households with people living alone.
	 */
	private String percentLivingAlone;
	
	/**
	 * The percentage of the households with people living alone over 65 years old.
	 */
	private String percentLivingAloneOver65;
	
	/**
	 * The average household size for the place.
	 */
	private String averageHouseholdSize;
	
	/**
	 * The average family size for the place.
	 */
	private String averageFamilySize;
	
	/**
	 * The number of houses in the area.
	 */
	private String numberOfHouses;
	
	/**
	 * Contains all of the stats about the place
	 */
	private String[] stats = new String[29];
	
	/**
	 * The total area of land in the place.
	 */
	private String areaLand;
	
	/**
	 * The total area of water in the place.
	 */
	private String areaWater;
	
	/**
	 * The estimated population as of 2011
	 */
	private String populationEstimate2011;
	
	/**
	 * The sumlev code given to the particular place by the census
	 */
	private String sumlev;
	
	/**
	 * The state code given to the particular place by the census
	 */
	private String state;
	
	/**
	 * The place code given to the particular place by the census
	 */
	private String place;
	
	/**
	 * The estimated population as of 2012
	 */
	private String populationEstimate2012;
	
	public static class CityBuilder{
		private String name;
		private String type;
		private String totalPopulation;
		private String percentUnder18;
		private String percent18to24;
		private String percent25to44;
		private String percent45to64;
		private String percentOver65;
		private String medianAge;
		private String percentMale;
		private String percentFemale;
		private String percentWhite;
		private String percentBlack;
		private String percentNative;
		private String percentAsian;
		private String percentPacific;
		private String percentOther;
		private String percentTwoOrMore;
		private String percentHispanic;
		private String households;
		private String families;
		private String percentWithChildren;
		private String percentHusbandAndWife;
		private String percentMaleNoWife;
		private String percentFemaleNoHusband;
		private String percentNonFamily;
		private String percentLivingAlone;
		private String percentLivingAloneOver65;
		private String averageHouseholdSize;
		private String averageFamilySize;
		private String numberOfHouses;
		private String areaLand;
		private String areaWater;
		private String populationEstimate2011;
		private String sumlev;
		private String state;
		private String place;
		private String populationEstimate2012;
		
		public CityBuilder(){};
		public CityBuilder name(String name){
			this.name = name;
			return this;
		}
		public CityBuilder type(String type){
			this.type = type;
			return this;
		}
		public CityBuilder totalPopulation(String totalPopulation){
			this.totalPopulation = totalPopulation;
			return this;
		}
		public CityBuilder percentUnder18(String percent){
			this.percentUnder18 = percent;
			return this;
		}
		public CityBuilder percent18to24(String percent){
			this.percent18to24 = percent;
			return this;
		}
		public CityBuilder percent25to44(String percent){
			this.percent25to44 = percent;
			return this;
		}
		public CityBuilder percent45to64(String percent){
			this.percent45to64 = percent;
			return this;
		}
		public CityBuilder percentOver65(String percent){
			this.percentOver65 = percent;
			return this;
		}
		public CityBuilder medianAge(String age){
			this.medianAge = age;
			return this;
		}
		public CityBuilder percentMale(String percent){
			this.percentMale = percent;
			return this;
		}
		public CityBuilder percentFemale(String percent){
			this.percentFemale = percent;
			return this;
		}
		public CityBuilder percentWhite(String percent){
			this.percentWhite = percent;
			return this;
		}
		public CityBuilder percentBlack(String percent){
			this.percentBlack = percent;
			return this;
		}
		public CityBuilder percentNative(String percent){
			this.percentNative = percent;
			return this;
		}
		public CityBuilder percentAsian(String percent){
			this.percentAsian = percent;
			return this;
		}
		public CityBuilder percentPacific(String percent){
			this.percentPacific = percent;
			return this;
		}
		public CityBuilder percentOther(String percent){
			this.percentOther = percent;
			return this;
		}
		public CityBuilder percentTwoOrMore(String percent){
			this.percentTwoOrMore = percent;
			return this;
		}
		public CityBuilder percentHispanic(String percent){
			this.percentHispanic = percent;
			return this;
		}
		public CityBuilder households(String households){
			this.households = households;
			return this;
		}
		public CityBuilder families(String families){
			this.families = families;
			return this;
		}
		public CityBuilder percentWithChildren(String percent){
			this.percentWithChildren = percent;
			return this;
		}
		public CityBuilder percentHusbandAndWife(String percent){
			this.percentHusbandAndWife = percent;
			return this;
		}
		public CityBuilder percentMaleNoWife(String percent){
			this.percentMaleNoWife = percent;
			return this;
		}
		public CityBuilder percentFemaleNoHusband(String percent){
			this.percentFemaleNoHusband = percent;
			return this;
		}
		public CityBuilder percentNonFamily(String percent){
			this.percentNonFamily = percent;
			return this;
		}
		public CityBuilder percentLivingAlone(String percent){
			this.percentLivingAlone = percent;
			return this;
		}
		public CityBuilder percentLivingAloneOver65(String percent){
			this.percentLivingAloneOver65 = percent;
			return this;
		}
		public CityBuilder averageHouseholdSize(String size){
			this.averageHouseholdSize = size;
			return this;
		}
		public CityBuilder averageFamilySize(String size){
			this.averageFamilySize = size;
			return this;
		}
		public CityBuilder numberOfHouses(String number){
			this.numberOfHouses = number;
			return this;
		}
		public CityBuilder areaLand(String land){
			this.areaLand = land;
			return this;
		}
		public CityBuilder areaWater(String water){
			this.areaWater = water;
			return this;
		}
		public CityBuilder populationEstimate2011(String value){
			this.populationEstimate2011 = value;
			return this;
		}
		public CityBuilder sumlev(String code){
			this.sumlev = code;
			return this;
		}
		public CityBuilder state(String code){
			this.state = code;
			return this;
		}
		public CityBuilder place(String code){
			this.place = code;
			return this;
		}
		public CityBuilder populationEstimate2012(String value){
			this.populationEstimate2012 = value;
			return this;
		}
		
		
		public City build(){
			City ret = new City();
			ret.name = name;
			ret.type = type;
			ret.totalPopulation = totalPopulation;
			ret.percentUnder18 = percentUnder18;
			ret.percent18to24 = percent18to24;
			ret.percent25to44 = percent25to44;
			ret.percent45to64 = percent45to64;
			ret.percentOver65 = percentOver65;
			ret.medianAge = medianAge;
			ret.percentMale = percentMale;
			ret.percentFemale = percentFemale;
			ret.percentWhite = percentWhite;
			ret.percentBlack = percentBlack;
			ret.percentNative = percentNative;
			ret.percentAsian = percentAsian;
			ret.percentPacific = percentPacific;
			ret.percentOther = percentOther;
			ret.percentTwoOrMore = percentTwoOrMore;
			ret.percentHispanic = percentHispanic;
			ret.households = households;
			ret.families = families;
			ret.percentWithChildren = percentWithChildren;
			ret.percentHusbandAndWife = percentHusbandAndWife;
			ret.percentMaleNoWife = percentMaleNoWife;
			ret.percentFemaleNoHusband = percentFemaleNoHusband;
			ret.percentNonFamily = percentNonFamily;
			ret.percentLivingAlone = percentLivingAlone;
			ret.percentLivingAloneOver65 = percentLivingAloneOver65;
			ret.averageHouseholdSize = averageHouseholdSize;
			ret.averageFamilySize = averageFamilySize;
			ret.numberOfHouses = numberOfHouses;
			ret.areaLand = areaLand;
			ret.areaWater = areaWater;
			ret.populationEstimate2011 = populationEstimate2011;
			ret.sumlev = sumlev;
			ret.state = state;
			ret.place = place;
			ret.populationEstimate2012 = populationEstimate2012;
			
			return ret;
		}
	}
	
	private City(){}
	
	public City(String url, DataStorage store){
		name = store.getName(url);
		type = store.getType(url);
		totalPopulation = store.getTotalPopulation(url);
		percentUnder18 = store.getPercentUnder18(url);
		percent18to24 = store.getPercent18to24(url);
		percent25to44 = store.getPercent25to44(url);
		percent45to64 = store.getPercent45to64(url);
		percentOver65 = store.getPercentOver65(url);
		medianAge = store.getMedianAge(url);
		percentMale = store.getPercentMale(url);
		percentFemale = store.getPercentFemale(url);
		percentWhite = store.getPercentWhite(url);
		percentBlack = store.getPercentBlack(url);
		percentNative = store.getPercentNative(url);
		percentAsian = store.getPercentAsian(url);
		percentPacific = store.getPercentPacific(url);
		percentOther = store.getPercentOther(url);
		percentTwoOrMore = store.getPercentTwoOrMore(url);
		percentHispanic = store.getPercentHispanic(url);
		households = store.getHouseholds(url);
		families = store.getFamilies(url);
		percentWithChildren = store.getPercentWithChildren(url);
		percentHusbandAndWife = store.getPercentHusbandAndWife(url);
		percentMaleNoWife = store.getPercentMaleNoWife(url);
		percentFemaleNoHusband = store.getPercentFemaleNoHusband(url);
		percentNonFamily = store.getPercentNonFamily(url);
		percentLivingAlone = store.getPercentLivingAlone(url);
		percentLivingAloneOver65 = store.getPercentLivingAloneOver65(url);
		averageHouseholdSize = store.getAverageHouseholdSize(url);
		averageFamilySize = store.getAverageFamilySize(url);
		numberOfHouses = store.getNumberOfHouses(url);
		areaLand = store.getAreaLand(url);
		areaWater = store.getAreaWater(url);
		populationEstimate2011 = store.getPopulationEstimate2011(url);
		sumlev = store.getSumlev(url);
		state = store.getState(url);
		place = store.getPlace(url);
		populationEstimate2012 = store.getPopulationEstimate2012(url);
	}
	
	/**
	 * Constructs City object by getting the needed information out of the files.
	 * @param demo is the File containing all of the demographic information about the city.
	 * @param area is the File containing the area information for the city.
	 * @param name is the name of the city.
	 * @deprecated do not use this for anything other than building the new files, it is unextendible and a legacy constructor
	 */
	@Deprecated
	public City(File demo, File area, String name){
		this.name = name;
		try{
			BufferedReader demoReader = new BufferedReader(new FileReader(demo));
			BufferedReader areaReader = new BufferedReader(new FileReader(area));
			//get the demographic info
			String line = demoReader.readLine();
			int start = 0;
			int end = 0;
			while (line != null){
				boolean falsePositive = false;
				//find the city in the file
				if (line.length() > name.length() && line.substring(0, name.length()).equals(name)){
					boolean typeFound = false;
					falsePositive = false;
					int statsInc = 0;
					//find the first number
					for (int i = 0; i < line.length(); i++){
						if (!typeFound && line.charAt(i) >= '0' && line.charAt(i) <= '9'){
							//find the empty space and parse out the type
							for (int j = i - 2; j > 0; j--){
								if (line.charAt(j) == ' '){
									type = line.substring(j + 1, i - 1);
									//check to see if this line is a false positive
									String falseCheck = line.substring(0, j);
									if (!name.equals(falseCheck)){
										falsePositive = true;
									}
									typeFound = true;
									break;
								}
							}
							//set start to first digit of the first number
							start = i;
						}
						if (falsePositive){
							break;
						}
						else if (typeFound && line.charAt(i) == ' '){
							end = i;
							stats[statsInc] = line.substring(start, end);
							start = i + 1;
							statsInc++;
						}
						else if (i == line.length() - 1){
							start = end  + 1;
							end = line.length();
							stats[statsInc] = line.substring(start, end);
							statsInc++;
						}
					}
					//exit since the city has been found
					if (!falsePositive){
						break;
					}
				}
				line = demoReader.readLine();
			}
			//if line is null at end of while loop then the city wasn't found in the file
			if (line == null){
				throw new IllegalArgumentException("The city was not found in the demographics file");
			}
			
			//skip over the first line since it is just headings
//			areaReader.readLine();
			line = areaReader.readLine();
			boolean areaFound = false;
			int infoFound = 0;
			//get area information
			while (line != null){
				boolean falsePositive = false;
				if (!areaFound && line.substring(20, 20 + name.length()).equals(name)){
					//make sure it isn't a false positive
					for (int i = 20; i < line.length(); i++){
						if (line.charAt(i) >= '0' && line.charAt(i) <= '9'){
							//found first number now go back to end of the
							int falseCheckEnd = -1;
							for (int j = i - 2; j >= 20; j--){
								if (line.charAt(j) == ' '){
									falseCheckEnd = j;
									break;
								}
							}
							if (!line.substring(20, falseCheckEnd).equals(name)){
								falsePositive = true;
							}
							break;
						}
					}
					if (!falsePositive){
						areaFound = true;
						//pick out the two areas
						for (int i = 20 + name.length(); i < line.length(); i++){
							//look for a period
							if (line.charAt(i) == '.'){
								//start point will be right after a non number
								for (int j = i - 1; j > 0; j--){
									if (!(line.charAt(j) >= '0' && line.charAt(j) <= '9')){
										start = j + 1;
										break;
									}
								}
								//end point will be right after the last number
								for (int j = i + 1; j < line.length(); j++){
									if (!(line.charAt(j) >= '0' && line.charAt(j) <= '9')){
										end = j;
										break;
									}
								}

								//pick out area of land
								if (infoFound == 0){
									areaLand = line.substring(start, end);
									infoFound++;
								}
								//pick out area of water
								else if (infoFound == 1){
									areaWater = line.substring(start, end);
									infoFound++;
								}
								//exit both values have been picked out
								else{
									break;
								}
							}
						}
					}
				}
				//exit since data has been found
				else if (areaFound){
					break;
				}
				
				if (!areaFound){
					line = areaReader.readLine();
				}
			}
			//if the line is null at the end of the loop then the city wasn't found in the file
			if (line == null){
				throw new IllegalArgumentException("The city was not found in the area file");
			}
			demoReader.close();
			areaReader.close();
			
			totalPopulation = stats[0];
			percentUnder18 = stats[1];
			percent18to24 = stats[2];
			percent25to44 = stats[3];
			percent45to64 = stats[4];
			percentOver65 = stats[5];
			medianAge = stats[6];
			percentMale = stats[7];
			percentFemale = stats[8];
			percentWhite = stats[9];
			percentBlack = stats[10];
			percentNative = stats[11];
			percentAsian = stats[12];
			percentPacific = stats[13];
			percentOther = stats[14];
			percentTwoOrMore = stats[15];
			percentHispanic = stats[16];
			households = stats[17];
			families = stats[18];
			percentWithChildren = stats[19];
			percentHusbandAndWife = stats[20];
			percentMaleNoWife = stats[21];
			percentFemaleNoHusband = stats[22];
			percentNonFamily = stats[23];
			percentLivingAlone = stats[24];
			percentLivingAloneOver65 = stats[25];
			averageHouseholdSize = stats[26];
			averageFamilySize = stats[27];
			numberOfHouses = stats[28];
		} 
		catch (FileNotFoundException e){
			e.printStackTrace();
		}
		catch (IOException e2){
			e2.printStackTrace();
		}
	}
	
	
	/**
	 * Gets the name of the place.
	 * @return The name of the place.
	 */
	public String getName(){
		return name;
	}
	
	/**
	 * Gets the type of the places.
	 * @return What the type of the city is ex: city or CDP.
	 */
	public String getType(){
		return type;
	}
	
	/**
	 * Gets the total population of the place.
	 * @return The total population of the place.
	 */
	public String getTotalPopulation(){
		return totalPopulation;
	}
	
	/**
	 * Gets the percentage population under the age of 18.
	 * @return The percentage population under the age of 18.
	 */
	public String getPercentUnder18(){
		return percentUnder18;
	}
	
	/**
	 * Gets the percentage population between the ages of 18 and 24.
	 * @return The percentage population between the ages of 18 and 24.
	 */
	public String getPercent18to24(){
		return percent18to24;
	}
	
	/**
	 * Gets the percentage population between the ages of 25 and 44.
	 * @return The percentage population between the ages of 25 and 44.
	 */
	public String getPercent25to44(){
		return percent25to44;
	}
	
	/**
	 * Gets the percentage population between the ages of 45 and 64.
	 * @return The percentage population between the ages of 45 and 64.
	 */
	public String getPercent45to64(){
		return percent45to64;
	}
	
	/**
	 * Gets the percentage of population over 65 years old.
	 * @return The percentage of population over 65 years old.
	 */
	public String getPercentOver65(){
		return percentOver65;
	}
	
	/**
	 * Gets the median age for the place.
	 * @return The median age of the place.
	 */
	public String getMedianAge(){
		return medianAge;
	}
	
	/**
	 * Gets the percentage of the population that is male.
	 * @return The percentage of the population that is male.
	 */
	public String getPercentMale(){
		return percentMale;
	}
	
	/**
	 * Gets the percentage of the population that is female.
	 * @return The percentage of the population that is female.
	 */
	public String getPercentFemale(){
		return percentFemale;
	}
	
	/**
	 * Gets the percentage of the population that is White.
	 * @return The percentage of the population that is White.
	 */
	public String getPercentWhite(){
		return percentWhite;
	}
	
	/**
	 * Gets the percentage of the population that is African American.
	 * @return The percentage of the population that is African American.
	 */
	public String getPercentBlack(){
		return percentBlack;
	}
	
	/**
	 * Gets the percentage of the population that is Native American.
	 * @return The percentage of the population that is Native American.
	 */
	public String getPercentNative(){
		return percentNative;
	}
	
	/**
	 * Gets the percentage of the population that is Asian.
	 * @return The percentage of the population that is Asian.
	 */
	public String getPercentAsian(){
		return percentAsian;
	}
	
	/**
	 * Gets the percentage of the population that is Pacific Islander.
	 * @return The percentage of the population that is Pacific Islander.
	 */
	public String getPercentPacific(){
		return percentPacific;
	}
	
	/**
	 * Gets the percentage of the population that is an other race.
	 * @return The percentage of the population that is an other race.
	 */
	public String getPercentOther(){
		return percentOther;
	}
	
	/**
	 * Gets the percentage of the population that is two or more races.
	 * @return The percentage of the population that is two or more races.
	 */
	public String getPercentTwoOrMore(){
		return percentTwoOrMore;
	}
	
	/**
	 * Gets the percentage of the population that is Hispanic.
	 * @return The percentage of the population that is Hispanic.
	 */
	public String getPercentHispanic(){
		return percentHispanic;
	}
	
	/**
	 * Gets the number of households in the place.
	 * @return The number of households in the place.
	 */
	public String getHouseholds(){
		return households;
	}
	
	/**
	 * Gets the number of families in the place.
	 * @return The number of families in the place.
	 */
	public String getFamilies(){
		return families;
	}
	
	/**
	 * Gets the percentage of the households with children.
	 * @return The percentage of the households with children.
	 */
	public String getPercentWithChildren(){
		return percentWithChildren;
	}
	
	/**
	 * Gets the percentage of the households that are husband and wife.
	 * @return The percentage of the households that are husband and wife.
	 */
	public String getPercentHusbandAndWife(){
		return percentHusbandAndWife;
	}
	
	/**
	 * Gets the percentage of the households that are a male with no wife.
	 * @return The percentage of the households that are a male with no wife.
	 */
	public String getPercentMaleNoWife(){
		return percentMaleNoWife;
	}
	
	/**
	 * Gets the percentage of the households that are a female with no husband.
	 * @return The percentage of the households that are a female with no husband.
	 */
	public String getPercentFemaleNoHusband(){
		return percentFemaleNoHusband;
	}
	
	/**
	 * Gets the percentage of the households that aren't a family.
	 * @return The percentage of the households that aren't a family.
	 */
	public String getPercentNonFamily(){
		return percentNonFamily;
	}
	
	/**
	 * Gets the percentage of the households with people living alone.
	 * @return The percentage of the households with people living alone.
	 */
	public String getPercentLivingAlone(){
		return percentLivingAlone;
	}
	
	/**
	 * Gets the percentage of the households with people living alone over 65 years old.
	 * @return The percentage of the households with people living alone over 65 years old.
	 */
	public String getPercentLivingAloneOver65(){
		return percentLivingAloneOver65;
	}
	
	/**
	 * Gets the average household size for the place.
	 * @return The average household size for the place.
	 */
	public String getAverageHouseholdSize(){
		return averageHouseholdSize;
	}
	
	/**
	 * Gets the average family size for the place.
	 * @return The average family size for the place.
	 */
	public String getAverageFamilySize(){
		return averageFamilySize;
	}
	
	/**
	 * Gets the number of houses in the area.
	 * @return The number of houses in the area.
	 */
	public String getNumberOfHouses(){
		return numberOfHouses;
	}
	
	/**
	 * Gets the amount of land in the place in square miles.
	 * @return The amount of land in the place in square miles.
	 */
	public String getAreaLand(){
		return areaLand;
	}
	
	/**
	 * Gets the amount of water in the place in square miles.
	 * @return The amount of water in the place in square miles.
	 */
	public String getAreaWater(){
		return areaWater;
	}
	
	/**
	 * Gets the population estimate in the place for the year 2011
	 * @return The population as estimated by census for 2011
	 */
	public String getPopulationEstimate2011(){
		return populationEstimate2011;
	}
	
	/**
	 * Gets the sumlev code that is assigned to the place by the census
	 * @return The sumlev code for the place
	 */
	public String getSumlev(){
		return sumlev;
	}
	
	/**
	 * Gets the state code that is assigned to the place by the census
	 * @return The state code for the place
	 */
	public String getState(){
		return state;
	}
	
	/**
	 * Gets the place code that is assigned to the place by the census
	 * @return The place code for the place
	 */
	public String getPlace(){
		return place;
	}
	
	/**
	 * Gets the population estimate in the place for the year 2012
	 * @return The population as estimated by census for 2012
	 */
	public String getPopulationEstimate2012(){
		return populationEstimate2012;
	}
	
	/**
	 * Calculates the population density in people per square mile for the place.
	 * @param digitsOfPrecision is the number of decimal points that should be used for the area value in the calculation.
	 * @return The population density in people per square mile.
	 */
	public String getPopulationDensityMile(int digitsOfPrecision){
		double land = Util.round(Double.parseDouble(areaLand), digitsOfPrecision);
		String popCopy = new String(totalPopulation);
		String popNoCommas = Util.removeCommas(popCopy);
		double pop = Double.parseDouble(popNoCommas);
		return Util.calculateDensity(pop, land);
	}
	
	/**
	 * Calculates the population density in people per square kilometer for the place.
	 * @param digitsOfPrecision is the number of decimal points that should be used for the area value in the calculation.
	 * @return The population density in people per square mile.
	 */
	public String getPopulationDensityKm(int digitsOfPrecision){
		return Util.format(Double.parseDouble(getPopulationDensityMile(digitsOfPrecision)) / 2.58998811, 1, false);
	}
	
	/**
	 * Calculates the house density in people per square mile for the place.
	 * @param digitsOfPrecision is the number of decimal points that should be used for the area value in the calculation.
	 * @return The house density in people per square mile.
	 */
	public String getHouseDensityMile(int digitsOfPrecision){
		double land = Util.round(Double.parseDouble(areaLand), digitsOfPrecision);
		String housesCopy = new String(numberOfHouses);
		String housesNoCommas = Util.removeCommas(housesCopy);
		double houses = Double.parseDouble(housesNoCommas);
		return Util.calculateDensity(houses, land);
	}
	
	/**
	 * Calculates the house density in people per square kilometer for the place.
	 * @param digitsOfPrecision is the number of decimal points that should be used for the area value in the calculation.
	 * @return The house density in people per square mile.
	 */
	public String getHouseDensityKm(int digitsOfPrecision){
		double land = Util.round(Double.parseDouble(areaLand), digitsOfPrecision);
		double landKm = Util.convertToSqKm(land);
		String housesCopy = new String(numberOfHouses);
		String housesNoCommas = Util.removeCommas(housesCopy);
		double houses = Double.parseDouble(housesNoCommas);
		return Util.calculateDensity(houses, landKm);
	}
}
